<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui" > 

<h:head></h:head> 
<body> 
<ui:composition template="../WEB-INF/layout/template.xhtml">
	<ui:define name="title"><h:outputText value="#{msg.search}" /></ui:define>
	<ui:define name="content">
		
		<p:tabView>
			<p:tab title="#{msg.search}">
				<h:panelGrid columns="1">
				
					<h:panelGrid columns="2">				
						<p:fieldset id="searchStudentFieldset">
							<big>#{msg.search_students}</big>
							<h:form>
								<h:panelGrid columns="2">
									<h:panelGroup>
										<h:outputText value="#{msg.search_by_name}" /><br/>
										<p:autoComplete id="firstName" value="#{searchStudentBean.firstName}"
											completeMethod="#{searchStudentBean.completeStudentName}"/>
									</h:panelGroup>
									<h:panelGroup>
										<h:outputText value="#{msg.search_by_town}" /><br/>
										<h:selectOneMenu value="#{searchStudentBean.studentTown}" style="width:145px" 
											hideNoSelectionOption="false">
											<f:selectItems value="#{searchStudentBean.townOptions}"/>
											<p:ajax event="change" listener="#{searchStudentBean.studentTownChanged}"></p:ajax>
										</h:selectOneMenu>
									</h:panelGroup>
									<h:panelGroup>
										<h:outputText value="#{msg.search_by_surname}" /><br/>
										<p:autoComplete id="surname" value="#{searchStudentBean.surname}"
											completeMethod="#{searchStudentBean.completeStudentSurname}"/>
									</h:panelGroup>
									<h:panelGroup>
										<h:outputText value="#{msg.search_by_school}" /><br/>
										<h:selectOneMenu value="#{searchStudentBean.schoolId}" style="width:145px">
											<f:selectItems value="#{searchStudentBean.schoolOptions}"/>
											<p:ajax update="courseCategorySOM"/>
										</h:selectOneMenu>
									</h:panelGroup>
									<h:panelGroup>
										<h:outputText value="#{msg.search_by_email}" /><br/>
										<p:autoComplete id="email" value="#{searchStudentBean.email}"
										completeMethod="#{searchStudentBean.completeStudentEmail}"/>
									</h:panelGroup>
									<h:panelGroup>
										<h:outputText value="#{msg.search_by_service}" /><br/>
										<h:selectOneMenu id="courseCategorySOM" value="#{searchStudentBean.courseCategoryId}" style="width:145px">
											<f:selectItems value="#{searchStudentBean.categoryOptions}"/>
										</h:selectOneMenu>
									</h:panelGroup>
								</h:panelGrid>
								<p:commandButton value="#{msg.submit}" action="#{searchStudentBean.submit}"
									update="studentSearchResultPanel growl">
									<f:setPropertyActionListener target="#{searchStudentBean.showResults}" value="true" />
									<f:setPropertyActionListener target="#{searchSchoolBean.showResults}" value="false" />
								</p:commandButton>
							</h:form>
						</p:fieldset>
						
						<p:fieldset id="searchSchoolFieldset">
							<h:form id="searchSchoolForm">
								<big>#{msg.search_school}</big>
								<h:panelGrid columns="1">
									<h:panelGroup>
										<h:panelGrid columns="2">
											<h:panelGroup>
												<h:outputText value="#{msg.search_by_name}" /><br/>
												<p:autoComplete id="schoolTown" 
													value="#{searchSchoolBean.schoolName}" 
													completeMethod="#{searchSchoolBean.completeSchoolName}"/>
											</h:panelGroup>
											<h:panelGroup>
												<h:outputText value="#{msg.search_by_town}" /><br/>
												<h:selectOneMenu value="#{searchSchoolBean.schoolTown}" style="width:145px">
													<f:selectItems value="#{searchSchoolBean.townOptions}"/>
												</h:selectOneMenu>
											</h:panelGroup>
										</h:panelGrid>
									</h:panelGroup>		
									<h:panelGroup>
										<h:outputText value="#{msg.search_by_service}"/><br/>
										<h:selectOneMenu value="#{searchSchoolBean.courseCategoryId}" style="width:145px">
											<f:selectItems value="#{searchSchoolBean.categoryOptions}"/>
										</h:selectOneMenu>
									</h:panelGroup>
									<h:panelGroup>
										<h:outputText value="#{msg.search_by_price}" /><br/>
										<h:outputText value="#{msg.min}" />
										<p:spinner value="#{searchSchoolBean.minPrice}" 
											min="0"
											size="6"/>
										<h:outputText value="#{msg.max}" />
										<p:spinner value="#{searchSchoolBean.maxPrice}" 
											min="0" 
											size="6"/>
									</h:panelGroup>
								</h:panelGrid>
								<p:commandButton value="#{msg.submit}" action="#{searchSchoolBean.submit}"
									update="schoolSearchResultPanel growl">
									<f:setPropertyActionListener target="#{searchStudentBean.showResults}" value="false" />
									<f:setPropertyActionListener target="#{searchSchoolBean.showResults}" value="true" />
								</p:commandButton>
							</h:form>
						</p:fieldset>
					</h:panelGrid>
					
					<p:ajaxStatus >  
						<f:facet name="start">  
							<h:graphicImage value="../resources/images/ajaxloading.gif" />  
						</f:facet>  
						<f:facet name="complete">  
							<h:outputText value="" />  
						</f:facet>  
					</p:ajaxStatus>
					
					<p:outputPanel style="width:900px">
						<p:panel id="studentSearchResultPanel" toggleable="true" header="#{msg.search_student_results}">
							<h:form id="studentSearchResultForm">
								<p:dataTable id="studentSearchResultTable" 
										value="#{searchStudentBean.searchStudentResult}" 
										var="student">
									<p:column sortBy="#{student.firstName}">
										<f:facet name="header">
											<h:outputText value="#{msg.first_name}"/>
										</f:facet>
										<h:outputText value="#{student.firstName}"/>
									</p:column>
									<p:column sortBy="#{student.surname}">
										<f:facet name="header">
											<h:outputText value="#{msg.surname}"/>
										</f:facet>
										<h:outputText value="#{student.surname}"/>
									</p:column>
									<p:column>
										<f:facet name="header">
											<h:outputText value="#{msg.town}"/>
										</f:facet>
										<h:outputText value="#{student.indirizzoIt.citta}"/>
									</p:column>
									<p:column>
										<f:facet name="header">
											<h:outputText value="#{msg.emails}"/>
										</f:facet>
										<ui:repeat value="#{student.emails}" var="email">
											<h:outputLink value="mailto:#{email.email}">
													<h:outputText value="#{email.email}"/>
											</h:outputLink>
											<br/>	
										</ui:repeat>
									</p:column>
									<p:column>
										<f:facet name="header">
											<h:outputText value="#{msg.phones}"/>
										</f:facet>
										<ui:repeat value="#{student.telephones}" var="telephone">
											<h:outputText value="#{telephone.number}"/><br/>
										</ui:repeat>
									</p:column>
									<p:column>
										<f:facet name="header">
											<h:outputText value="#{msg.enrollments}"/>
										</f:facet>
										<p:dataTable value="#{student.iscrizioni}" var="enrollment">
											<p:column>
												<f:facet name="header">
													<h:outputText value="#{msg.course}"/>
												</f:facet>
												<h:outputText value="#{enrollment.corso.name}"/>
											</p:column>
											<p:column>
												<f:facet name="header">
													<h:outputText value="#{msg.category}"/>
												</f:facet>
												<h:outputText value="#{enrollment.corso.categoria.name}"/>
											</p:column>
<!--											<p:column>-->
<!--												<f:facet name="header">-->
<!--													<h:outputText value="#{msg.from}"/>-->
<!--												</f:facet>-->
<!--												<h:outputText value="#{enrollment.startDate}"/>-->
<!--											</p:column>-->
<!--											<p:column>-->
<!--												<f:facet name="header">-->
<!--													<h:outputText value="#{msg.to}"/>-->
<!--												</f:facet>-->
<!--												<h:outputText value="#{enrollment.endDate}"/>-->
<!--											</p:column>-->
											<p:column>
												<f:facet name="header">
													<h:outputText value="#{msg.price}"/>
												</f:facet>
												<h:outputText value="#{enrollment.totalCost}"/>
											</p:column>
										</p:dataTable>
									</p:column>
									<p:column>
										<p:commandButton value="E" action="#{nav.inserisciStudente}">
											<f:setPropertyActionListener value="#{student}" target="#{inserisciStudenteBean.studentInput}" />
										</p:commandButton>
									</p:column>
								</p:dataTable>
							</h:form>
						</p:panel>
						
						<p:panel id="schoolSearchResultPanel" toggleable="true" header="#{msg.search_school_results}">
							<h:form id="schoolSearchResultForm">
								<p:dataTable id="schoolSearchResultTable" 
										value="#{searchSchoolBean.searchSchoolResult}" 
										var="school">
									<p:column>
										<h:outputText value="#{school.id}"/>
									</p:column>
									<p:column sortBy="#{school.ragioneSociale}">
										<f:facet name="header">
											<h:outputText value="#{msg.name}"/>
										</f:facet>
<!--										<h:link outcome="inserisciScuola" value="#{school.ragioneSociale}">-->
<!--											<f:param name="id" value="#{school.id}" />-->
<!--										</h:link>-->
										<h:outputText value="#{school.ragioneSociale}"/>
									</p:column>
									<p:column sortBy="#{school.indirizzo.citta}">
										<f:facet name="header">
											<h:outputText value="#{msg.town}"/>
										</f:facet>
										<h:outputText value="#{school.indirizzo.citta}"/>
									</p:column>
									<p:column>
										<f:facet name="header">
											<h:outputText value="#{msg.address_line_1}"/>
										</f:facet>
										<h:outputText value="#{school.indirizzo.indirizzoLinea1}"/>
									</p:column>
									<p:column>
										<f:facet name="header">
											<h:outputText value="#{msg.branches}"/>
										</f:facet>
										<p:dataTable value="#{school.branches}" var="branch">
											<p:column>
												<f:facet name="header">
													<h:outputText value="#{msg.name}" />
												</f:facet>
												<h:outputText value="#{branch.name}"/>
											</p:column>
											<p:column>
												<f:facet name="header">
													<h:outputText value="#{msg.town}" />
												</f:facet>
												<h:outputText value="#{branch.indirizzo.citta}"/>
											</p:column>
										</p:dataTable>
									</p:column>
									<p:column>
										<p:commandButton value="E" action="#{nav.inserisciScuola}">
											<f:setPropertyActionListener value="#{school}" target="#{inserisciScuolaBean.schoolInput}" />
										</p:commandButton>
										<p:commandButton value="E2" action="#{nav.inserisciScuola}">
											<f:setPropertyActionListener value="#{school.id}" target="#{inserisciScuolaBean.id}" actionListener="#{inserisciScuolaBean.postConstruct}"/>
										</p:commandButton>
									</p:column>
								</p:dataTable>
							</h:form>
						</p:panel>
					</p:outputPanel>
					
				</h:panelGrid>
			</p:tab>
		</p:tabView>
		
		<p:growl id="growl"></p:growl>

	</ui:define>
</ui:composition>
</body> 
</html>
